#ifndef __RSTRING_H__
#define __RSTRING_H__

#include <string.h>

typedef struct _rstring_t
{
	int ref;
	int size;
	int length;
	char *content;
} rstring_t;

void rstring_ref(rstring_t *self);
void rstring_unref(rstring_t *self);
void rstring_release(rstring_t **self);

rstring_t *rstring_new(void);
rstring_t *rstring_new_char(char ch);
rstring_t *rstring_new_string(const char *s);

void rstring_append(rstring_t *self, char ch);
char rstring_is_one_of(rstring_t *self, int count, ...);

static inline char rstring_at(rstring_t *self, int index)
{
	return index < 0 || index >= self->length ? 0 : self->content[index];
}

static inline char rstring_equals(rstring_t *self, const char *s)
{
	int len = (int)strlen(s);
	return self->length == len && !memcmp(s, self->content, len);
}

static inline char rstring_equals_rs(rstring_t *self, rstring_t *s)
{
	return (self->length == s->length) && !memcmp(self->content, s->content, s->length);
}

#endif /* __RSTRING_H__ */
